import type * as T from './type';

import { requestClient } from '#/api/request';

export type * from './type';

const BASE_URL = '/captcha';

/** @desc 获取图片验证码 */
export function getImageCaptcha() {
  return requestClient.get<T.ImageCaptchaResp>(`${BASE_URL}/image`);
}

/** @desc 获取短信验证码 */
export function getSmsCaptcha(phone: string, captchaReq: T.BehaviorCaptchaReq) {
  return requestClient.get<boolean>(
    `${BASE_URL}/sms?phone=${phone}&captchaVerification=${encodeURIComponent(captchaReq.captchaVerification || '')}`,
  );
}

/** @desc 获取邮箱验证码 */
export function getEmailCaptcha(
  email: string,
  captchaReq: T.BehaviorCaptchaReq,
) {
  return requestClient.get<boolean>(
    `${BASE_URL}/mail?email=${email}&captchaVerification=${encodeURIComponent(captchaReq.captchaVerification || '')}`,
  );
}

/** @desc 获取行为验证码 */
export function getBehaviorCaptcha(req: any) {
  return requestClient.get<T.BehaviorCaptchaResp>(`${BASE_URL}/behavior`, req);
}

/** @desc 校验行为验证码 */
export function checkBehaviorCaptcha(req: any) {
  return requestClient.post<T.CheckBehaviorCaptchaResp>(
    `${BASE_URL}/behavior`,
    req,
  );
}
